using HCore.Unity.Core;

namespace HCore.Tests.Runtime.Minesweeper.Scripts
{
    public class MapGridObject
    {
        private readonly Grid2D<MapGridObject> mGrid2D;
        private bool isFlagged;


        public MapGridObject(Grid2D<MapGridObject> grid, int x, int y)
        {
            mGrid2D = grid;
            X = x;
            Y = y;
            GridType = GridType.Empty;
            Revealed = false;
        }

        public int X { get; }
        public int Y { get; }

        public bool Revealed { get; private set; }

        public GridType GridType { get; set; }

        public void SetFlagged(bool flagged)
        {
            isFlagged = flagged;
            mGrid2D.TriggerCellChanged(X, Y);
        }

        public bool Flagged()
        {
            return isFlagged;
        }

        public override string ToString()
        {
            return $"{GridType}";
        }

        /// <summary>
        ///     翻开格子
        /// </summary>
        public void Reveal()
        {
            if (Revealed) return;
            Revealed = true;
            mGrid2D.TriggerCellChanged(X, Y);
        }
    }

    public enum GridType
    {
        Empty, // 撒都没有
        Mine, // 雷
        MineNum1, // 数字1
        MineNum2,
        MineNum3,
        MineNum4,
        MineNum5,
        MineNum6,
        MineNum7,
        MineNum8 // 数字8 
    }
}